<template>
	<view class="page">
		<uni-nav-bar left-icon="back" class="nav_bar" fixed="true" backgroundColor="#fff" color="#808080"
			statusBar='true' @clickLeft="onNarLeftClick()">
			<view class="bar-title">问答互动消息</view>
		</uni-nav-bar>
		<view v-if="questionMessageList.data.length>0" class='messages-clear-all'>
			<view class='number-of-messages'>{{questionMessageList.data.length}}条</view>
			<view class='clear-all-button' @click="onDeleteAllQuestionMessageClick">清除全部</view>
		</view>
		<view v-if="questionMessageList.data.length>0" class="interactive-list-content">
			<interactive-message-item
			v-for="(item,index) in questionMessageList.data"
			:key="item.createTime"
			:interactiveData="item"
			@onClick="onQuestionMessageItemClick(item)"
			:messageType="'QUESTION'"
			>
			</interactive-message-item>
		</view>
		<view v-else class='no-message'>
			<view class='iconfont icon-message' :style="{fontSize: '300rpx'}" />
			<view class='no-message-text'>暂时没有互动消息</view>
		</view>
	</view>
</template>

<script lang="ts">
	import {getQuestionMessageList,deleteQuestionMessageList,
			saveQuestionMessageList,getMyUserInfo
	} from "@/common/storageFunctions";
	import {changeUnreadMessageSum} from "@/utils/tabBarBadgeUtils";
	import {
		COMMENT_ON_ISSUE,
		COMMENT_ON_COMMENT,
		COMMENT_ON_SON_OR_GRANTSON_COMMENT,
		LIKE_ON_ISSUE,
		LIKE_ON_COMMENT,
		LIKE_ON_SON_COMMENT
	} from "@/common/constants";
	/**
	 * questionMessage 问答板块的互动消息
	 * @description 问答板块的互动消息
	 * @Author: 穆兰
	 * @Date: 2022/2/20
	 * @LastEditors: 穆兰
	 * @LastEditTime: 2022/2/20
	 */
	export default {
		data() {
			return {
				userInfo:{},
				questionMessageList:{unreadSum:0,data:[]},
			}
		},
		async onLoad(params){
			this.userInfo = await getMyUserInfo()
			if(this.userInfo.id){
				let questionMessageList = await getQuestionMessageList(this.userInfo.id,this.type)
				this.questionMessageList=questionMessageList
				changeUnreadMessageSum(-questionMessageList.unreadSum)
				questionMessageList.unreadSum=0
				saveQuestionMessageList(this.userInfo.id,questionMessageList)
			}
		},
		computed:{
		},
		methods: {
			onNarLeftClick() {
				uni.navigateBack({
					delta: 1
				});
			},
			/**
			 * @description 点击某个互动消息时
			 * @param {Object} item
			 */
			onQuestionMessageItemClick(item){
				console.log("onQuestionMessageItemClick")
				if (item.type === COMMENT_ON_ISSUE || item.type === LIKE_ON_ISSUE) {
				  uni.navigateTo({
					url: `/pages/activity-info/question-info/question-info?questionId=${item.issueId}`
				  })
				} else if (item.type === COMMENT_ON_COMMENT|| item.type === COMMENT_ON_SON_OR_GRANTSON_COMMENT
				||item.type === LIKE_ON_COMMENT ||item.type===LIKE_ON_SON_COMMENT
				) {
				  uni.navigateTo({ url: `/pages/activity-info/answer-info/answer-info?answerId=${item.eventId}&questionId=${item.issueId}` })
				}
			},
			onDeleteAllQuestionMessageClick(){
				let _this = this
				uni.showModal({
					title:"清除全部",
					content:"你确定要清除所有消息吗？",
					success:function (res){
						if(res.confirm){
							deleteQuestionMessageList(_this.userInfo.id)
							_this.questionMessageList={unreadSum:0,data:[]}
							uni.showToast({
								title:"清除成功"
							})
						}
						
					}
					
				})
				
			}
		}
	}
</script>

<style lang="scss">
.no-message{
		width: 100%;
		height: 100vh;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		text-align: center;
		color:#dadada
	}
	.no-message-text{
		margin-top: 20rpx;
		font-size: large;
		color: #b6b6b6;
	}
	.messages-clear-all{
		display: flex;
		align-items: center;
		justify-content: center;
		margin: 2%;
		.number-of-messages{
			flex: 1;
			color: #b1b1b1;
		}
		.clear-all-button{
		padding: 5rpx 20rpx;
		border-radius: 10rpx;
		font-size: small;
		color: #777575;
		background-color: #eeeeee;
		}
	}
</style>
